import Taro from "@tarojs/taro";
import { View } from "@tarojs/components";
import { useEffect,useState  } from "react";
import {getSpecialInfo} from '../../api/mode'
import {SpecialRecruitCard} from '../../components'
import './index.scss'

export default function SpecialRecruit(props){
  const [recruitInfo,setRecruitInfo]=useState()
    //分页
    const [specialNum,setSpecialNum]=useState(1)
    const [specialFlag,setSpecialFlag]=useState(false)


    useEffect(()=>{
      setSpecialNum(props.pageNum)
    },[props.pageNum])

    
  const params={
    page:specialNum,
    size:5,
  }

//初始化
  useEffect(()=>{
    getSpecialInfo(params).then(
      res=>{
        setRecruitInfo(res.data.data.records)
      }
    )
  },[])

  //分页
  useEffect(()=>{
    if(specialNum>1&&!specialFlag){
      getSpecialInfo(params).then(
        res=>{
          if(!res.data.data.records.length){
            setSpecialFlag(true)
            Taro.showToast({
              title:'没有更多了',
              icon:'error',
              duration:2000
            })
  
          }
          setRecruitInfo([
            ...recruitInfo,
            ...res.data.data.records,
          ])

        }
      )
    }

  },[props.pageNum])


  return(
    <View>
      <View >
      {recruitInfo?recruitInfo.map((Info,index)=>(<SpecialRecruitCard key={index} Info={Info}></SpecialRecruitCard>)):null}
      </View>
    </View>
  )
}